var express = require('express');
var router = express.Router();
var multiparty = require('multiparty')

/* GET home page. */
router.get('/', function(req, res, next) {
    req.session.userinfo = {username:123,role:1};
    res.send(JSON.stringify({
        title: 'title'
    }));
});

router.post('/login', function (req, res, next) {
    if (Math.random() > 0.5) {
        res.send({msg: '登录成功'})
    } else {
        res.status(400)
        res.send({msg: '用户名或密码错误'})
    }
})
router.get('/logout', function (req, res, next) {
    res.send({msg: '注销成功'})
})

router.post('/register', function (req, res, next) {
    if (Math.random() > 0.8) {
        res.status(423)
        res.send({msg: '用户名已存在'})
    } else if(Math.random() > 0.6) {
        res.status(400)
        res.send({msg: '注册失败'})
    } else {
        res.send({msg: '注册成功'})
    }
})

module.exports = router;
